import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main3{
    public static int len(List<Integer>ret,int left,int right,int p,int k){
        int leftMin=left,rightMin=right;
        int leftMax=left,rightMax=right;

        while (leftMin<rightMin){
            int mid=leftMin+(rightMin-leftMin)/2;
            if(k-ret.get(mid)<=p){
                rightMin=mid;
            }else {
                leftMin=mid+1;
            }
        }
        while (leftMax<rightMax){
            int mid=leftMax+(rightMax-leftMax+1)/2;
            if(ret.get(mid)-k<=p){
                leftMax=mid;
            }else {
                rightMax=mid-1;
            }
        }
        return leftMax-rightMin+1;
            }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int p = in.nextInt();
        List<Integer> ret = new ArrayList<>();
        for(int i=0;i<n;i++){
            ret.add(in.nextInt());
        }
    Collections.sort(ret);

        int temp=0;
        int minVal=ret.get(0)-p;
        int maxVal=ret.get(n-1)+p;

        for(int i=minVal;i<=maxVal;i++){
            temp=Math.max(temp,len(ret,0,n-1,p,i));
        }
        System.out.println(temp);
    }

    }
